package com.qmai.demo;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.qmai.openapi.*;
import com.qmai.util.dto.Result;

import java.time.LocalDateTime;

/**
 * 交易查询 demo
 */
public class OrderQueryDemo {
	public static void main(String[] args) {
		try{
			QPayClient qPayClient = new DefaultQPayClient("https://qpay.qmai.cn/gateway.do", "03b4a52ce6891319a040cec4d4de4454", "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCkWV80FtKyJcL2m8gi8Ccmc3IiY+9YMfOw/LnkOR+XjIK5IcJEfsA6FdYi1XpCQIW8j79pB4Us2oZphy4cdPLy2KC/qTUDtH3RLNAMoyvSF2CrqttydYkbZIYG/ReORFmklTTGHMYsOh950CoJSZs/hhdKHkkRD7U5lDVA2MYTTrt/SWXoVzH6rpZcCaHur6WboKT/xZLBdyxJ+O+QKuHaPa8l1ZtYOo/Sh4IHXTU8Oc6Jz9WRUDxQd4P3XPUeMoTsfvf96sxVGpsSAZZrw/G0CPrDNfT2UNnB17v3lvIkgxVVV7y+XGvOtYLc6btcsCOpjC3flwZ3QcOFvmwxwqbpAgMBAAECggEALMFlyrKYaAkegbfElbcegjsYDsN2L2dS/JSmLr9bmhKamr3VwH9f67F8ofnOlHIruUDQGFMC8kcEKYK1jOxQKM/TXr4+gKbLSIZSlc5tpYXWPomFvzLAxqPmV8reelCktMwpFfZKBUtCvRJyEBtqWq8ycm2y6iGD8Y0pv2II9sKeNEfNmG/yqaIXZZUL7AJuwjvO6c+D6vrtbN4exA5S0MSNWu6tTtwV7CwamRymKTQjEB+jSZJCsGpJJiSmAoORTWl9ieCmDqLKGZlRhfzKSFPoArZa151ALcW1OaxSRXfFaVKCKVRqMF+Ofc6hruOQzGC0Yc7l2FvhZYKxG03YDQKBgQDsiO3qRDwqNWQ768k035RnvJ3W23zO8qJid4zXHJzHt021pIhjHjz+77Ko1im5VP96++iNtRqYFOtQk9EesH7b8P0hd357psx/LU8drnshWv4d2nUc8TwOljzeE1JLBOsWVx1yZ8pjBJHcKOzH6SGL5/jVGMYv3QrS09ChuPScpwKBgQCx37U1F9ONUhibesJyz2nO0tMb3SGQ82k3PfeC9EOLBgsC9xwSuSVNaFFUiM/GHzkeHl4dts512SlY3SxVA2dECwB4BUQF/KBZBcTNPIM0e40/EliY0eoQvTbJpYiLYoXd5liJBj/SEdlsEsW/Z0KwJFtDvaGqVSpzMUZixzJB7wKBgGjrPA0kA0P9tt5VckR/wAZbxe+eIDhzq8/dk51/VZPJHTErMEw3B3tVu3vks1FAAKr+vmLNKGS5Mr/lMWdZhovs03ta08HpdOAcqvFRidB72ihH1Jbn8mnN/mXLUD9yiQy5y5gJrd5KEqEDjjQGlxjF5rwvZwmoFLr7tZlmvyoVAoGAPZ7yd+I5N8wpGjP9CSkxzqTa3dxNtJme6bRd+tAEVjVRu0VARHw/oAFzq4V59Xj7oKOEl2atP8ZrvI1ivlDfhYMKNoocdrZ+FlkZRMCh85yZ4i/I4ahXHlVulYzzMNaA6c7S/SVdFrl4SSh3uUdcowj1VRJs30WB30ZCzBWWI6ECgYEAsywPbusg+3t14KIlPYERtzgcxdlKb2KpsHh3YptqRST8elsHBA3cLYvEN5g/YcIduHC0X0iqkyoaA6oxQP5XKjSZoaPrRCRLqiWd3h9+rhs+g0ABb5bUv16KnGE0BCEVX0d/LCjWIimoRH7zXuhvBtnNoNk1AFDZ8oF7R1Las3c=");
			OrderQueryRequest orderQueryRequest = new OrderQueryRequest();
			orderQueryRequest.setMerchantNo("834010410201001");
			orderQueryRequest.setOutTradeNo("6019061814560900000097207348");
			orderQueryRequest.setPayTrace("1234567890111");
			orderQueryRequest.setPayType("010");
			orderQueryRequest.setTerminalNo("2202008132154268484");
			orderQueryRequest.setTerminalTrace("12345678902");
			orderQueryRequest.setTerminalTime(LocalDateTime.now());
			QmaiRequest qmaiRequest = new QmaiRequest(JSON.toJSONString(orderQueryRequest, DefaultQPayClient.SNAKE_CASE_CONFIG));
			Result<String> execute = qPayClient.execute("qpay.trade.query", qmaiRequest, String.class);
			System.out.println(execute);
		} catch (Exception e) {
			System.err.println("调用遭遇异常，原因：" + e.getMessage());
			throw new RuntimeException(e.getMessage(), e);
		}
	}
}
